    <%--
      Created by IntelliJ IDEA.
      User: Administrator
      Date: 2017/10/22
      Time: 19:46
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" import="inspur.dao.UserDao,inspur.entity.User,inspur.dao.LoginDao,inspur.common.FiledCheck,inspur.dao.cookieDao" %>
    <%@ page import="java.net.URLEncoder" %>
    <%@ page import="java.util.Date" %>
    <%@ page import="inspur.entity.CookieTokenObject" %>
    <%@ page import="inspur.common.Sha1" %>
    <%@page import="org.apache.commons.codec.digest.DigestUtils" %>
    <%@ include file="config.jsp"%>
    <%!
        //login=login        正在登陆
        //login=error        登陆错误
                                //请重新登陆
        //login=success      登陆成功
                                //跳转到新页面（主页）
        String login="login";
    %>


<html>
<head>
    <title><%=webTitle%></title>
    <meta name="Keywords" content="<%=keywords%>">
    <meta name="Description" content="<%=Description%>">
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery-2.1.3.min.js"></script>
</head>
<body>
    <div align="center">
        <%@include file="component/top.jsp"%><!---顶栏-->
        <%@include file="component/checkBox.jsp"%><!--搜索框-->

        <%
            String userIdError="";
            String passWordError="";
            String userNameError="";
            String[] checkbox=null;
            int remberDay=-1;
            //从表单里面获得用户名和密码的值
            request.setCharacterEncoding("utf-8");
            //String username=request.getParameter("UserId");
            String id=request.getParameter("UserId");
            String password=request.getParameter("UserPassWord");
            checkbox=request.getParameterValues("check");
            if (checkbox==null){
                System.out.println("rember=null");
            }else {
                    System.out.println("rember=7");
                    remberDay=7;

            }
            if (id==null){
                id="";
            }
            if (password==null){
                password="";
            }

            //非空的校验
            if(FiledCheck.isBlack(id)){
                //用户名不能为空
               // request.setAttribute("usernameError", "用户名不能为空");
                //请求转发
               // request.getRequestDispatcher("/login.jsp").forward(request, response);

            }else if(FiledCheck.isBlack(password)){
                //密码不能为空
               // request.setAttribute("passwordError", "密码不能为空");
                //请求转发
               // request.getRequestDispatcher("/login.jsp").forward(request, response);

            }else{



                //登录信息的校验
                User user=new User();
                user.setId(id);
                user.setPassword(password);

                LoginDao loginDao=new LoginDao();
                int num=loginDao.login(user);
                if(num==2){
                    // num=2,登陆成功
                    String token_userid=id;
                    String token_password=password;
                    String token_ip=request.getRemoteAddr();
                    System.out.println(token_userid+"-"+token_password+"-"+token_ip);
                    CookieTokenObject Token=new CookieTokenObject(token_userid,token_ip,token_password,remberDay);
                    cookieDao.addCookieToken(response,Token);//安装cookieToken令牌到计算机
                    response.sendRedirect(request.getContextPath() + "index.jsp");
                }else{
                    //用户名 或者密码错误
                    if(num==1){
                        passWordError="密码错误";
                       // request.setAttribute("passwordError", "密码错误");
                    }else{
                        //用户名不存在 或者 错误
                        //request.setAttribute("usernameError", "用户名错误");
                        userIdError="用户名不存在 或者 错误";
                    }
                    //请求转发
                    //request.getRequestDispatcher("/login.jsp").forward(request, response);
                    System.out.println("hello ");

                }

            }







        %>
        <%

        %>
            <table>
                <tr>
                    <td>
                        <form  action="" method="post">
                            <p align="left" >
                                账户名：<input type=text class="box2" id="user" name="UserId" value='<%=id%>'><%=userIdError%><br><br>
                                密码：&nbsp&nbsp&nbsp<input type=password class="box2" id="password" name="UserPassWord" value='<%=password%>'><%=passWordError%><br><br>
                                验证码：<input type=text  class="box2" name="one_message" value='请忽略该项'><br><br>
                                记住密码(7天):<input  name="check" id="check" type="checkbox" style="zoom: 150%; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="a2" href="">忘记密码</a><br><br>
                                <input type="submit" class="bt500x50" name='tj' value='登录系统' >
                            </P>
                        </form>
                    </td>
                </tr>
            </table>



    </div>
</body>
</html>
